var projectlist = [];
var obj;
//加载table项目列表
function loadProjectList() {
    projectlist = [];  
    var tpgkUrl = "http://www.fqghj.net:8887/arcgis/rest/services/YDHX/HXTEMP/MapServer/0"
    var queryTask = new QueryTask({
        url: tpgkUrl
    });
    var query = new Query();
    query.where = "1=1";
    // and PRJNAME like '%'";
    //返回所有字段
    query.outFields = ["*"];
    //返回几何信息。
    query.returnGeometry = true;
    queryTask.execute(query).then(function(evt) {
        if (evt != null) {
            if (evt.features.length > 0) {
                for (var i = 0; i < evt.features.length; i++) {
                    projectlist.push(evt.features[i]);
                    var tr = $("<tr prjid=\"" + evt.features[i].attributes["PRJID"] + "\">");
                    var td_name = $("<td>");
                    td_name.append(evt.features[i].attributes["PRJNAME"]);
                    tr.append(td_name);
                    $("#tb_project").append(tr);
                    $(document).on("click", "#tb_project tr", function() {
                        selectTr(this);
                    });
                }
            }
        }
    })
}

//定位选中项目地块
function selectTr(obj) {
    var prjLayer = new GraphicsLayer();
    var prjid = $(obj).attr("prjid");
    if (projectlist.length > 0) {
        for (var i = 0; i < projectlist.length; i++) {
            if (projectlist[i].attributes["PRJID"] == prjid) {
                var graphic = new Graphic({
                    geometry: projectlist[i].geometry,
                    symbol: {
                        type: "simple-fill",
                        color: [255, 255, 255],
                        style: "solid",
                        outline: {
                            color: [255, 0, 0],
                            width: 2
                        }
                    }
                });
                prjLayer.graphics.add(graphic);
                map.add(prjLayer);
                var sExtent = new Extent({
                    xmin: projectlist[i].geometry.extent.xmin - 500,
                    ymin: projectlist[i].geometry.extent.ymin - 500,
                    xmax: projectlist[i].geometry.extent.xmax + 500,
                    ymax: projectlist[i].geometry.extent.ymax + 500,
                    spatialReference: {
                        wkid: 4549
                    }
                });
                view.extent = sExtent;
            }
        }
    }
}